﻿using System.Configuration;
using System;
using System.Data;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;

/// <summary>
/// DbHelper 的摘要说明
/// </summary>
namespace KeDa2025_.Utils
{
    public  class DbHelper
    {


        /// <summary>
        /// 查询数据库，并且返回一个数据容器
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns>返回查询结果的数据集</returns>
        public static DataSet Query(string sql)
        {
            MySqlConnection connection = new MySqlConnection("server=localhost;user id=zmy2;password=zmy20020525;database=forum;");
            MySqlDataAdapter sqlDataAdapter = new MySqlDataAdapter(sql, connection);
            DataSet ds = new DataSet();

            // 打开连接
            connection.Open();
            // 填充数据集
            sqlDataAdapter.Fill(ds);
            // 关闭连接
            connection.Close();

            return ds;
        }
        public int Execute(string sql)
        {
            MySqlConnection conn = new MySqlConnection("server=localhost;user id=zmy2;password=zmy20020525;database=forum;");
            MySqlCommand cmd = new MySqlCommand(sql, conn);

            // 打开连接
            conn.Open();
            // 执行非查询 SQL 语句
            int flag = cmd.ExecuteNonQuery();
            // 关闭连接
            conn.Close();
            return flag;
        }
    }



}